require 'Qt4'
class HZVaultDD < Qt::Widget
	signals 'valueChanged(int)'
	slots 'display(int)'
	
	def initialize(parent = nil)
		super()
		@size = Qt::Label.new()
		@slider = Qt::Slider.new(Qt::Horizontal)
		@slider.setStyleSheet("
				      QSlider::groove:horizontal {
				      border: 1px solid #696969;
				      height: 8px; /* the groove expands to the size of the slider by default. by giving it a height, it has a fixed size */
				      background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #696969);
								  }
				      QSlider::handle:horizontal {
				      background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #7e7e7e, stop:1 #8f8f8f);
				      border: 1px solid #5c5c5c;
				      width: 18px;
				      margin: -2px 0; /* handle is placed by default on the contents rect of the groove. Expand outside the groove */
				      border-radius: 3px;
				      }")
		@slider.setRange(0, `df -k / | grep -e "^.*[0-9][0-9][0-9]*.*$" | sed -e "s/\s\s*/ /g" | cut -d " " -f 4`.to_i/(1024*1024))
		@slider.setValue(2)
		@size.setText("2 GB (Max: " + @slider.maximum.to_s + " GB)")
		
		connect(@slider, SIGNAL('valueChanged(int)'), self, SLOT('display(int)'))
		
		layout = Qt::HBoxLayout.new()
		layout.addWidget(@slider)
		layout.addWidget(@size)
		setLayout(layout)
	end
	
	def value
		@slider.value
	end
	
	def display(value)
		@size.setText(value.to_s + " GB (Max: " + @slider.maximum.to_s + " GB)")
	end
end
